package com.greenhouse9.prog06;

import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

public class head {
    public static void main (String[] args){

        if ( args.length < 1 ) {
            /* �g�p��@�̕\�� */
            usage();
            System.exit(0);
        }

        if ( args.length > 0 ) {
            File fd = new File(args[0]);
            if ( !fd.exists() ) {
                System.out.println(fd.getName() + ": �t�@�C�������݂��܂���B");
                System.exit(1);
            }
            if ( fd.isDirectory()) {
                System.out.println(fd.getName() + "�̓f�B���N�g���ł��B");
                System.exit(1);
            }

            try {
                BufferedReader br = new BufferedReader(new FileReader(fd));
                String line;
                int    lineCount = 0;

                while((line = br.readLine()) != null) {
                    lineCount = lineCount + 1;
                    if ( lineCount > 10 ) {
                        break;
                    }
                    System.out.println(line);
                }

                br.close();
            }
            catch (IOException e){
                e.printStackTrace();
            }
        }
    }

    private static void usage() {
        System.out.println("java head filename");
    }

}